package com.kfm.bootmybatis.controller;

import com.kfm.bootmybatis.model.UserModel;
import com.kfm.bootmybatis.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping({"/", "/login"})
    public ModelAndView hello(){
        return new ModelAndView("login");
    }


    @PostMapping("/login")
    public ModelAndView login(UserModel userModel){
        if(userService.login(userModel)!= null){
            return new ModelAndView("index");
        }
        return new ModelAndView("redirect:login");
    }
}
